package com.wc.acwing.动态规划.线性DP.杨老师的照相排列;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/15 22:02
 * f[a][b][c][d][e] 表示第一行为a人，第二行为b人第三行为c人，第四行为d人，第五行为e人的方案数
 *                  其中a <= b <= c <= d <= e
 * @description https://www.acwing.com/problem/content/273/
 */
public class Main {
    static int N = 30 + 2;
    static long[][][][][] f = new long[N][N][N][N][N];
    static int k;
    static int[] n = new int[5 + 1];
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        while (sc.hasNext()) {
            k = sc.nextInt();
            if (k == 0) {
                break;
            }
            for (int a = 0; a < N; a++) {
                for (int b = 0; b < N; b++) {
                    for (int c = 0; c < N; c++) {
                        for (int d = 0; d < N; d++) {
                            for (int e = 0; e < N; e++) {
                                f[a][b][c][d][e] = 0;
                            }
                        }
                    }
                }
            }
            f[0][0][0][0][0] = 1;
            Arrays.fill(n, 0);
            for (int i = 1; i <= k; i++) {
                n[i] = sc.nextInt();
            }
            for (int a = 0; a <= n[1]; a++) {
                for (int b = 0; b <= Math.min(a, n[2]); b++) {
                    for (int c = 0; c <= Math.min(b, n[3]); c++) {
                        for (int d = 0; d <= Math.min(c, n[4]); d++) {
                            for (int e = 0; e <= Math.min(d, n[5]); e++) {
                                if (a > 0 && a - 1 >= b) {
                                    f[a][b][c][d][e] += f[a - 1][b][c][d][e];
                                }
                                if (b > 0 && b - 1 >= c) {
                                    f[a][b][c][d][e] += f[a][b - 1][c][d][e];
                                }
                                if (c > 0 && c - 1 >= d) {
                                    f[a][b][c][d][e] += f[a][b][c - 1][d][e];
                                }
                                if (d > 0 && d - 1 >= e) {
                                    f[a][b][c][d][e] += f[a][b][c][d - 1][e];
                                }
                                if (e > 0) {
                                    f[a][b][c][d][e] += f[a][b][c][d][e - 1];
                                }
                            }
                        }
                    }
                }
            }
            out.println(f[n[1]][n[2]][n[3]][n[4]][n[5]]);
        }
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
        st = new StringTokenizer("");
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }
}
